package chapter07

object Demo12_DerivedCollection {
  def main(args: Array[String]): Unit = {
    val list1 = List(1,2,3,4,5,4,3,2,2)
    val list2 = List(3,4,5,6,33,4,4,3,2,2,3,3,3)
//    (1)获取集合的头
    println(list1.head )
//    (2）获取集合的尾（不是头的就是尾)
    println(list1.tail)
//    (3）集合最后一个数据
    println(list2.last)
//    (4）集合初始数据（不包含最后一个)  不是最后一个的前面所有的元素
    println(list2.init)
//    (5）反转
    println(list2.reverse)
//    (6）取前(后)n个元素
    println(list2.take(3))
    println(list2.takeRight(2))
//    (7）去掉前（后)n个元素
    println(list2.drop(3))
    println(list1.dropRight(1))

    println("======================")
//    (8）并集
    val union = list1.union(list2)
    println("union: " + union)
    println(list1 ::: list2)

    //如果是Set 做并集 会进行去重操作
    val set1 = Set(1,2,3,4,5,6,7,8)
    val set2 = Set(1,2,3,33,44,55,66,77)

    val union2 = set1.union(set2)
    println("union: " + union2)
//    (9）交集
    val intersection = list1.intersect(list2)
    println("intersection: " + intersection)
//    (10）差集
    val diff1 = list1.diff(list2)
    println("diff: " + diff1)
    println("-----------------------")
//    (11）拉链
    println(list1)
    println(list2)
    println("zip: " + list2.zip(list1))
    println("zip: " + list1.zip(list2) )
    println("------------------------")
//    (12）滑窗  要是步长等于窗口值的话叫滚动窗口
    for (elem <- list1.sliding(3)  ) println(elem)
    println("--------------")
    for (elem1 <- list1.sliding(3,2)  ) println(elem1)
  }
}
